﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace XPathTool {
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class XPathWindow : Window {
        //IModelView _VM;
        ModelView_MainWindow _VM;

        public XPathWindow() {
            InitializeComponent();
            _VM = new ModelView_MainWindow();
            _VM.CloseXmlForm += new CloseXmlFormEventHandler(_VM_CloseXmlForm);
            this.DataContext = _VM;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <remarks>
        /// Why is this not bound to the ModelView to implement MVVM? Answer:
        /// "A 'Binding' cannot be set on the 'SelectionStart' property of type 'TextBox'. 
        /// A 'Binding' can only be set on a DependencyProperty of a DependencyObject."
        /// </remarks>
        private void txtXml_SelectionChanged(object sender, RoutedEventArgs e) {
            _VM.SelectionStart = txtXml.SelectionStart;
            _VM.SelectedXml = txtXml.SelectedText;
        }

        void _VM_CloseXmlForm(object sender, EventArgs e) {
            this.Close();
        }

    }
}
